

import java.util.ArrayList;

public class SPiece extends Piece {
	public SPiece(int x, int y) {
		super(x,y);
	}

	@Override
	public void buildPiece() {
		ArrayList<Block> ipiece = new ArrayList<Block>();
		int x = this.getX();
		int y = this.getY();
		ipiece.add(new Block(x+1, y+0, S_ID));
		ipiece.add(new Block(x+2, y+0, S_ID));
		ipiece.add(new Block(x+0, y+1, S_ID));
		ipiece.add(new Block(x+1, y+1, S_ID));
		setPiece(ipiece);
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		int[][] blocks = new int[4][4];
		for (Block i : getPiece()) {
			blocks[i.getX()][i.getY()] = 1;
		}
		for (int x = 0; x < 4; x++) {
			for (int y = 0; y < 4; y++) {
				if (blocks[x][y] == 1) {
					sb.append("[]");
				} else {
					sb.append("  ");
				}
			}
			sb.append("\n");
		}
		return sb.toString();
	}

	@Override
	public void rotate() {
		ArrayList<Block> next_piece = new ArrayList<Block>();
		int r = getRotationNumber();
		if (r == 0 || r == 2) {
			next_piece.add(new Block(0 + getX(), 0 + getY(), S_ID));
			next_piece.add(new Block(0 + getX(), 1 + getY(), S_ID));
			next_piece.add(new Block(1 + getX(), 1 + getY(), S_ID));
			next_piece.add(new Block(1 + getX(), 2 + getY(), S_ID));
			setPiece(next_piece);
		} else {
			next_piece.add(new Block(1 + getX(), 0 + getY(), S_ID));
			next_piece.add(new Block(2 + getX(), 0 + getY(), S_ID));
			next_piece.add(new Block(1 + getX(), 1 + getY(), S_ID));
			next_piece.add(new Block(0 + getX(), 1 + getY(), S_ID));
			setPiece(next_piece);
		}
		super.rotate();
	}
}